home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / AmigaTalk / system / MsgPort.st < prev    next >
Encoding:
Text File  |  2004-01-31  |  2.9 KB  |  99 lines

  1. "---------------------------------------------------------------------"
  2. " MsgPort Class allows the User to communicate using MsgPorts, either "
  3. " within AmigaTalk programs, or to any defined MsgPort known to Exec. "
  4. ""
  5. "   WARNING!  WARNING!  Danger, Will Robinson!                        "
  6. "   You had better know what size & what Message any outside System   "
  7. "   MsgPort expects to see & respond to!                              "
  8. "---------------------------------------------------------------------"
  9.  
  10. Class MsgPort :Object ! private portName !
  11. [
  12.    killPort
  13.  
  14.       <primitive 191 0 private>.
  15.  
  16.       <primitive 250 5 0 private>. "One-way ticket to death!"
  17.       
  18.       ^ nil
  19. |
  20.    addPort: msgSize priority: priority
  21.     
  22.       " Register the MsgPort with the AmigaOS System PortList. 
  23.       * Use 'new: newPortName' method first! 
  24.       "
  25.       (<primitive 191 1 private msgSize priority> == nil)
  26.       
  27.         ifTrue: [ self error: 'MsgPort ', portName, ' NOT added to System!'.
  28.                   ^ false
  29.                 ].
  30.       ^ true
  31. |
  32.    getMessage
  33.     
  34.       " If no message ever gets sent, you'll freeze AmigaTalk!! "
  35.  
  36.       " This method has waitPort: getMsg: & replyMsg: built-in  "
  37.       
  38.       " Returns an array of bytes that represents the actual 
  39.       * message, not including the operating system overhead. 
  40.       "
  41.       ^ <primitive 191 2 private>  
  42. |
  43.    sendMessage: atalkMsgPortObj msg: bytesArray
  44.     
  45.       " This method has putMsg: & waitPort: (wait for a reply)
  46.       * built-in.  The reply is thrown away.
  47.       * bytesArray has to be <= than the size given with 
  48.       * addPort:priority:
  49.       "
  50.       <primitive 191 3 private atalkMsgPortObj bytesArray>
  51. |
  52.    selectMessagePort
  53.  
  54.       " Display a ListView of all known message Ports so that
  55.       * the User can select a msgPortObj to send messages to.
  56.       "
  57.       ^ <primitive 250 0 8>
  58. |
  59.    sendMessageOutsideTo: systemPortObj msg: bytesArray
  60.  
  61.       " This method has putMsg:, waitPort: & getMsg: built-in. "
  62.       " Send a message to a MsgPort outside the AmigaTalk System.
  63.       * WARNING!  WARNING!  Danger, Will Robinson!
  64.       * You had better know what size & what Message the port expects!
  65.       "
  66.       <primitive 191 7 private systemPortObj bytesArray>
  67. |
  68.    checkForPort
  69.  
  70.       " See if the MsgPort Object is known to the AmigaOS: "
  71.       ^ <primitive 191 4 private> "Return either true or false."
  72. |
  73.    getNamedSystemPort: sysPortName
  74.  
  75.       " Return a msgPortObj that represents the System Port Name given: "
  76.       ^ <primitive 191 5 sysPortName>
  77. |
  78.    getMsgPort
  79.  
  80.       " Returns this instance's msgPortObj "
  81.       ^ <primitive 191 8 private>
  82. |
  83.    new: newPortName
  84.  
  85.      " Allocate & initialize a new MsgPort for AmigaTalk: "
  86.      private  <- <primitive 191 6 newPortName>.
  87.  
  88.      portName <- newPortName.
  89.      
  90.      ^ self
  91. |
  92.    new
  93.  
  94.      " Maybe this should be: printClassUsedInError "
  95.      super new.
  96.      
  97.      ^ (self new: 'Default_AmigaTalk_MPort')
  98. ]
  99.